﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var conString = "server=.;database=Productid;uid=sa;pwd=123456;";
            SqlConnection sqlConnection = new SqlConnection(conString);
            sqlConnection.Open();
            Console.WriteLine("连接数据库成功！");
            Console.WriteLine("插入数据：");
            Console.WriteLine("姓名：");
            string name = Console.ReadLine();
            Console.WriteLine("学号：");
            int number = int.Parse(Console.ReadLine());

            var sql1 = "insert into Person(Name,Number)" + "Value('李明',22)";

            sql1 = "update Person set Number =29 where Name='张慧'";
            var cmdString = "select * from Employee";
            SqlCommand command = new SqlCommand(cmdString, sqlConnection);
            var reader = command.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}\t{3}","Id","Name", "Salary", "ManagerId");
            while (reader .Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", reader ["Id"], reader["Name"], reader["Salary"], reader["ManagerId"]);
            }
            sqlConnection.Close();

            DataTable table = new DataTable();
            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdString, conString);
            dataAdapter.Fill(table);
            Console.WriteLine();

        }
    }
}
